import 'dart:io';

import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

import 'ToastUtils.dart';

Future<void> saveFileBytes(BuildContext context,String name,List<int> fileBytes) async {
  var directory = await getExternalStorageDirectory();
  if (directory == null) {
    if (context.mounted) {
      showErrorToast(context, "无法打开外部储存");
    }
    return;
  }

  var path = '${directory.path}/$name';
  File(path)
    ..createSync(recursive: true)
    ..writeAsBytesSync(fileBytes);

  if (context.mounted) {
    showSuccessToast(context, "已保存至$path");
  }
}
